package com.juc.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class CompletableFutureDemo1 {

	public static void main(String[] args) {
		int h = 9;
		CompletableFuture.supplyAsync(()->{
			try {
				TimeUnit.SECONDS.sleep(2);
			} catch (Exception e2) {
				e2.printStackTrace();
			}
			return 1;
		}).thenApply(f-> {
			return f+h;
		}).whenComplete((v,e) ->{
			if (null == e) {
				System.out.println("---result --- " + v);
			}
		}).exceptionally(e->{
			e.printStackTrace();
			return null;
		});
		System.out.println("---main over----");
		
		try {
			TimeUnit.SECONDS.sleep(5);
		} catch (Exception e2) {
			e2.printStackTrace();
		}
	}
}
